package myRules;

import java.util.HashSet;

import se.lth.eit.eit060.proj2.initiation.Utility;

public class Record extends HashSet<String> {

	// HashSet contains associated.
	private String name;
	private String division;
	private String data;

	public Record(String division, String name, String data) {
		this.division = division;
		this.data = data;
		this.name = name;
	}

	// Check contains first always! Read you have to check agent as well!
	public boolean canWrite(String name, String title, String divison,String data) {
		if (divison.equals(this.division)) {
			System.out.println("DATA: " +data);
				this.data = data;
				return true;
		}else if(contains(name)){
			System.out.println("DATA: " +data);
			this.data = data;
			return true;
		}
		return false;
	}
	public String read(){
		return data;
	}
	public String getName(){
		return name;
	}
	
	public boolean canRead(String title, String division){
		if(title.equals(Utility.Agent)||division.equals(this.division)){
			return true;
		}
		return false;
	}

	public String getData() {
		return data;
	}
	public String toString(){
		String associates="";
		for(String s : this){
			associates+="A="+s+Utility.SPLIT;
		}
		String s =  division+Utility.SPLIT+name+Utility.SPLIT+associates+data;
		System.out.println("RECORD: "+s);
		return s;
	}


}
